# 显式等待直到找到指定的元素（最多等待10秒）
from lib2to3.pgen2 import driver
from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class Lt:
    def __init__(self, driver, username=None, password=None):
        self.driver = driver
        self.username = username
        self.password = password

    def log(self, username, password):
        self.username = username
        self.password = password
        loginButton = self.driver.find_element(By.CLASS_NAME, 'heaadRouteName')  # 使用 element_to_be_clickable 确保元素可点击

        # 点击元素
        loginButton.click()

        getInputUserName = self.driver.find_element(By.XPATH,
                                                    '/html/body/div[1]/div[2]/div/div/div[2]/div[1]/div[2]/form/div[1]/div/div/input')

        getInputUserName.click()
        getInputUserName.send_keys(self.username)

        getInputPassWord = self.driver.find_element(By.XPATH,
                                                    '/html/body/div[1]/div[2]/div/div/div[2]/div[1]/div[2]/form/div[2]/div/div/input')  # 继续进行其他操作...
        getInputPassWord.click()
        getInputPassWord.send_keys(self.password)

        getButtonSubmit = self.driver.find_element(By.XPATH,
                                                   '/html/body/div/div[2]/div/div/div[2]/div[1]/div[2]/form/div[4]/div/button')
        getButtonSubmit.click()


    def quit(self):
        actions = ActionChains(self.driver)
        getUserPic = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/div/div[4]/div/div/div[2]')
        actions.move_to_element(getUserPic).perform()
        sleep(1)

        getButtonOut = self.driver.find_element(By.XPATH, '/html/body/div[3]/div[4]')
        getButtonOut.click()
        sleep(3)

    def set_login(self, username, password):
        self.username = username
        self.password = password

    def set_login_username(self, username):
        self.username = username

    def set_login_password(self, password):
        self.password = password
